package javax.xianfeng.drools.hello;

import javax.xianfeng.drools.util.DroolsUtils;

import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import lombok.extern.slf4j.Slf4j;

/**
 * https://blog.csdn.net/chenhao_c_h/article/details/85090307
 * 
 * @since 2020/04/04 09:03:54
 */
@Slf4j
public class HelloTest1 {

	/**
	 * 执行drl文件（过滤规则）
	 * 
	 * @since 2020/04/07 21:40:32
	 */
	@Test
	public void hello() {
		KieServices kieServices = KieServices.Factory.get();
		KieContainer kieContainer = kieServices.newKieClasspathContainer();
		KieSession kieSession = kieContainer.newKieSession("session");

		try {
			// 执行kmodule配置的全部drl文件
			kieSession.fireAllRules();

			// 过滤kmodule配置的全部drl文件
			// 参考https://blog.csdn.net/a294634473/article/details/89456645
//			 kieSession.fireAllRules(new RuleNameStartsWithAgendaFilter("hello"));
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		} finally {
			DroolsUtils.closeSession(kieSession);
		}

	}

}
